import { defineStore } from 'pinia'
import { store } from '/@/store'
import type { AxiosResponse } from 'axios'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'

import accountService from '/@/api/cn/core/sign/accountService'

import type { Account } from '/@/model/cn/core/sign/eo/Account'
import type { AccountQO } from '/@/model/cn/core/sign/qo/AccountQO'
import type { AccountVO } from '/@/model/cn/core/sign/vo/AccountVO'

interface AccountState {
}

export const useAccountStore = defineStore({
  id: 'account',
  state: (): AccountState => ({
  }),
  getters: {
  },
  actions: {
    save(param: Param<Account>): Promise<Res<Account>> {
      return new Promise<Res<Account>>((resolve, reject) => {
        accountService.save(param).then((res: AxiosResponse<Res<Account>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    saveBatch(param: Param<Account>): Promise<Res<Account>> {
      return new Promise<Res<Account>>((resolve, reject) => {
        accountService.saveBatch(param).then((res: AxiosResponse<Res<Account>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    update(param: Param<Account>): Promise<Res<Account>> {
      return new Promise<Res<Account>>((resolve, reject) => {
        accountService.update(param).then((res: AxiosResponse<Res<Account>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    updateBatch(param: Param<Account>): Promise<Res<Account>> {
      return new Promise<Res<Account>>((resolve, reject) => {
        accountService.updateBatch(param).then((res: AxiosResponse<Res<Account>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    remove(param: Param<Account>): Promise<Res<Account>> {
      return new Promise<Res<Account>>((resolve, reject) => {
        accountService.remove(param).then((res: AxiosResponse<Res<Account>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    removeBatch(param: Param<Account>): Promise<Res<Account>> {
      return new Promise<Res<Account>>((resolve, reject) => {
        accountService.removeBatch(param).then((res: AxiosResponse<Res<Account>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    count(param: Param<AccountQO>): Promise<Res<Account>> {
      return new Promise<Res<Account>>((resolve, reject) => {
        accountService.count(param).then((res: AxiosResponse<Res<Account>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pk(param: Param<AccountQO>): Promise<Res<Account>> {
      return new Promise<Res<Account>>((resolve, reject) => {
        accountService.pk(param).then((res: AxiosResponse<Res<Account>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    query(param: Param<AccountQO>): Promise<Res<Account>> {
      return new Promise<Res<Account>>((resolve, reject) => {
        accountService.query(param).then((res: AxiosResponse<Res<Account>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    paging(param: Param<AccountQO>): Promise<Res<Account>> {
      return new Promise<Res<Account>>((resolve, reject) => {
        accountService.paging(param).then((res: AxiosResponse<Res<Account>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    countVo(param: Param<AccountQO>): Promise<Res<AccountVO>> {
      return new Promise<Res<AccountVO>>((resolve, reject) => {
        accountService.countVo(param).then((res: AxiosResponse<Res<AccountVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pkVo(param: Param<AccountQO>): Promise<Res<AccountVO>> {
      return new Promise<Res<AccountVO>>((resolve, reject) => {
        accountService.pkVo(param).then((res: AxiosResponse<Res<AccountVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    queryVo(param: Param<AccountQO>): Promise<Res<AccountVO>> {
      return new Promise<Res<AccountVO>>((resolve, reject) => {
        accountService.queryVo(param).then((res: AxiosResponse<Res<AccountVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pagingVo(param: Param<AccountQO>): Promise<Res<AccountVO>> {
      return new Promise<Res<AccountVO>>((resolve, reject) => {
        accountService.pagingVo(param).then((res: AxiosResponse<Res<AccountVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
  },
})

export function useAccountStoreWithout() {
  return useAccountStore(store)
}
